package com.boang.ch;

import java.io.*;

/*
    @author:sa
    @date:2024/12/12 10:28
*/
public class FileWriterDemo {
    public static void main(String[] args) throws IOException {
//        write();
//        read();
        //       read1();

        file();
    }

    private static void file() throws IOException {
        FileReader fileReader = new FileReader("fw.text");
        FileWriter fileWriter = new FileWriter("fw2.text", true);
        int i;
        while ((i = fileReader.read()) != -1) {
            fileWriter.write(i);
            System.out.println((char) i);
        }
        fileWriter.close();
        fileReader.close();
    }

    private static void read1() throws IOException {
        FileReader fileReader = new FileReader("fw.text");
        int i;
        while ((i = fileReader.read()) != -1) {
            System.out.println((char) i);
        }
    }

    private static void read() throws IOException {
        FileReader fileReader = new FileReader("fw.text");
        int i = fileReader.read();
        System.out.println(i);
        int i2 = fileReader.read();
        System.out.println(i2);
        int i3 = fileReader.read();
        System.out.println(i3);
        int i4 = fileReader.read();
        System.out.println(i4);
    }

    private static void write() throws IOException {
        FileWriter fileWriter = new FileWriter("fw.text", true);
        fileWriter.write("a");
        fileWriter.write("b");
        fileWriter.write("c");
        fileWriter.close();
    }
}